import { stringify } from 'qs';
import request from '@/utils/request';

/**
 *
 * @xzh {告警列表接口}
 */
export async function getWarningData(params){
    let url = `/iot/dmp/v1/warning/list`
    return request(url, {
      method: 'POST',
      body: {
        ...params
      },
    });
}

/**
 *
 * @xzh {列表接口}
 */
export async function getAlarmData(params){
  let url = `/iot/workflow/v1/workflow/tasklist`
  return request(url, {
    method: 'POST',
    body: {
      ...params
    },
  });
}

/**
 *
 * @xzh {告警详情接口}
 */
export async function getWarningInfo(params){
  let url = `/iot/dmp/v1/warning/${params.warning_id}`
  return request(url, {
    method: 'GET',
  });
}


/***
 * @xzh {告警列表}
 */
export async function getWarning(params) {
	return request('/iot/dmp/v1/warning/list', {
		method: 'POST',
		body: {
			...params,
			warning_status: 'CREATED'
		}
	})
}

/***
 * @xzh {告警详情}
 */
export async function getWarningDetail(params) {
	return request(`/iot/dmp/v1/device/${params.device_id}`, {
		method: 'get'
	})
}


/***
 * @xzh {部门树}
 */
export async function getDeptTree(params) {
	return request('/iot/dmp/v1/depts/tree', {
		method: 'POST',
		body: {
			...params
		}
	})
}

/***
 * @xzh {工单详情}
 */
export async function getDeviceOrder(params) {
	// console.log(params	)
	return request(`/iot/workflow/v1/workflow/select-task/${params.did}`, {
		method: 'get'
	})
}

/***
 * @xzh {动态记录}
 */
export async function getEventLog(params) {
	return request('/iot/dmp/v1/taskLog/list', {
		method: 'POST',
		body: {
			...params
		}
	})
}

/***
 * @xzh {流程图}
 */
export async function getWorkflow(params) {
	const url = `/iot/workflow/v1/workflow/generateImage/${params.process_instance_id}`;
	return request(url, {
	  reuqestImage :true,
	  method: 'get'
	})
}

/***
 * @xzh {部门下的用户}
 */
export async function getUser(params) {
	return request('/iot/dmp/v1/users/list', {
		method: 'POST',
		body: {
			...params,
			is_child_only: '1'
		}
	})
}

export async function taskAccept(params) {
	// console.log(queryString.stringify(params))
	return request(`/iot/workflow/v1/workflow/apply`, {
		method: 'POST',
		body: {
			...params
		}
	})
}
export async function uploadHandleRes(params) {
	return request('/iot/workflow/v1/workflow/complete', {
		method: 'fileUpload',
		reMethod: 'POST',
		body: {
			...params
		},
	}
	);
}
export async function cancelWarning(params) {
	return request(`/iot/dmp/v1/warning-close/${params.device_id}`)
}
